Report with two data levels (master-detail)

So far we examined reports where only one data-band was presented ("First level data"). That enabled typing data from one DB table. FastReport allows to type reports containing up to six data levels (it is also possible to type more levels via the "subreport" object; this feature will be examined later). In real applications, reports with large data applications are rarely typed. As a rule, they are limited to 1-3 levels.

Let us examine the two-leveled report creation process. It will contain data from the DBDEMOS tables: "Customer.db" è "Orders.db." The first table is the list of clients; the second one is the list of orders placed by the clients. The tables contain data of the following type:

Customer:

CustNo Company
1221 Kauai Dive Shoppe
1231 Unisco
1351 Sight Diver
….

Orders:

OrderNo CustNo SaleDate
1003 1351 12.04.1988
1023 1221 01.07.1988
1052 1351 06.01.1989
1055 1351 04.02.1989
1060 1231 28.02.1989
1123 1221 24.08.1993
….

As you can see, the second table contains the list of all the orders placed by all companies. To receive the list of orders placed by a particular company, the notes, in which the "CustNo" field contains the number of the chosen company, should be selected in the table. The report constructed on such data will look as follows:

1221 Kauai Dive Shoppe
1023 01.07.1988
1123 24.08.1993
1231 Unisco
1060 28.02.1989
1351 Sight Diver
1003 12.04.1988
1052 06.01.1989
1055 04.02.1989

Let us get down to the report creation. Create a new project in Delphi, put two "TTable," one "TDataSource", two "TfrxDBDataSet" and one "TfrxReport" components to the form. Set the components in the following way:

Table1:
DatabaseName = 'DBDEMOS'
TableName = 'Customer.db'

Table2:
DatabaseName = 'DBDEMOS'
TableName = 'Orders.db'

DataSource1:
DataSet = Table1

frxDBDataSet1:
DataSet = Table1
UserName = 'Customers'

frxDBDataSet2:
DataSet = Table2
UserName = 'Orders'

In the report designer, let us connect our data sources in the "Report|Data..." window. Put the "Master data" and "Detail data" bands on the page:

Note that the "Master Data" band must be allocated above the "Detail Data" band! If allocated under, FastReport will inform you about an error occurrence when the report starts.